#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int square_add(int n) {
        int sum = 0;
        int t = 0;
        while (n) {
            t = n % 10;
            sum += t * t;
            n /= 10;
        }
        return sum;
    }
    bool isHappy(int n) {
        int slow = n, fast = square_add(n);
        while (slow != fast) {
            slow = square_add(slow);
            fast = square_add(square_add(fast));//
        }
        return slow == 1;
    }
};